/**
 * Bone React Native App
 * https://open.aliplus.com/bone
 * @flow
 */

import React, {Component} from 'react';
import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import {NativeModules} from 'react-native'
const plugins = NativeModules.T11Plugin;
import T11Plugin_IOS from '../T11Plugin_IOS';

export default class Main extends Component {
    constructor(props, context) {
        super(props, context);
        this.state = {};
    }


    render() {
        // setTimeout(()=>{
        //     alert(222);
        // },2000);
        // console.log(ImagePicker)
        const url = 'http://www.team11.cn:9091/t11_gaokemei/uploadFile?fname=jtr123.png';//上传地址
        return (
            <View style={styles.container}>
                {this.state.iosScan?
                    (<T11Plugin_IOS
                        type={["scan",()=>{this.state.iosScan = false}]}
                        callback={(info,error)=>{
                            this.setState({
                                iosScan:false
                            });
                            this.scanGetUUID(info);
                        }}
                    />):(<Text style={{height:0}}></Text>)
                }
                {this.state.iosOpenPhoto?
                    (<T11Plugin_IOS
                        type={["openPhoto",()=>{this.state.iosOpenPhoto = false}]}
                        params={{url:url}}
                        callback={(sucess,error)=>{
                            this.setState({
                                iosOpenPhoto:false
                            });
                            alert(sucess);
                        }}
                    />):(<Text style={{height:0}}></Text>)
                }
                {this.state.iosOpenCamera?
                    (<T11Plugin_IOS
                        type={["openCamera",()=>{this.state.iosOpenCamera = false}]}
                        params={{url:url}}
                        callback={(sucess,error)=>{
                            this.setState({
                                iosOpenCamera:false
                            });
                            alert(sucess);
                        }}
                    />):(<Text style={{height:0}}></Text>)
                }
                <TouchableOpacity onPress={()=>{
                    // plugins.openPhoto(url)
                    this.setState({
                        iosOpenPhoto:true
                    })

                }}>
                    <View style={{'margin':20}}>
                        <Text>打开相册</Text>
                    </View>
                </TouchableOpacity>

                <TouchableOpacity onPress={()=>{
                    // plugins.openCamera(url)
                    this.setState({
                        iosOpenCamera:true
                    })
                }}>
                    <View>
                        <Text>打开相机</Text>
                    </View>
                </TouchableOpacity>
                <Text style={styles.welcome} onPress={()=>{

                }}>
                    Welcome to Bone React Native!
                </Text>

                <Text style={styles.instructions}>
                    To get started, view doc https://open.aliplus.com/bone
                </Text>
                <Text style={styles.instructions}>
                    Press Cmd+R to reload,{'\n'}
                    Cmd+D or shake for dev menu
                </Text>
                <TouchableOpacity onPress={this.context.nextPage} >
                    <Text>Go to detail page</Text>
                </TouchableOpacity>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF'
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5
    }
});
